package kr.pe.johnkim.checkmileage.mobile.rest.dao;

import kr.pe.johnkim.checkmileage.mobile.domain.CheckMileageMerchant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import java.util.List;

/**
 * Check Mileage 가맹점 관련 DAO 메소드들을 구현하는 클래스 이다.
 *
 * @author : johnkim <cale9797@gmail.com / Bettersoft, Inc.>
 * @Date : 12. 7. 25
 */
public class CheckMileageMerchantDaoImpl extends SqlMapClientDaoSupport implements CheckMileageMerchantDao {

    // SLF4J Logging
	private Logger logger = LoggerFactory.getLogger(CheckMileageMerchantDaoImpl.class);

    /**
     * 가맹점 중복 아이디 검사를 한다.
     *
     * @param checkMileageMerchant
     * @return
     */
    @Override
    public CheckMileageMerchant selectMerchantId(CheckMileageMerchant checkMileageMerchant) {
        logger.info("selectMerchantId");
        return (CheckMileageMerchant)getSqlMapClientTemplate().queryForObject("CHECKMILEAGE_MERCHANTS.selectMerchantId", checkMileageMerchant);
    }

    /**
     * 가맹점을 등록 한다.
     *
     * @param checkMileageMerchant
     */
    @Override
    public void registerMerchant(CheckMileageMerchant checkMileageMerchant) {
        logger.info("registerMerchant");

        getSqlMapClientTemplate().insert("CHECKMILEAGE_MERCHANTS.registerMerchant", checkMileageMerchant);
    }

    /**
     * 서비스 로그인을 한다.
     *
     * @param checkMileageMerchant
     * @return
     */
    @Override
    public CheckMileageMerchant login(CheckMileageMerchant checkMileageMerchant) {
        logger.info("login");

        return (CheckMileageMerchant)getSqlMapClientTemplate().queryForObject("CHECKMILEAGE_MERCHANTS.login", checkMileageMerchant);
    }


    /**
     * 가맹점 정보를 가져 온다.
     *
     * @param checkMileageMerchant
     * @return
     */
    @Override
    public CheckMileageMerchant selectMerchantInformation(CheckMileageMerchant checkMileageMerchant) {
        logger.info("selectMerchantInformation");

        return (CheckMileageMerchant)getSqlMapClientTemplate().queryForObject("CHECKMILEAGE_MERCHANTS.selectMerchantInformation", checkMileageMerchant);
    }

    /**
     * 가맹점 정보를 수정 한다.
     *
     * @param checkMileageMerchant
     */
    @Override
    public void updateMerchantInformation(CheckMileageMerchant checkMileageMerchant) {
        logger.info("updateMerchantInformation");

        getSqlMapClientTemplate().update("CHECKMILEAGE_MERCHANTS.updateMerchantInformation", checkMileageMerchant);
    }

    /**
     * 가맹점의 서비스 사용을 제한 여부를 업데이트 한다.
     *
     * @param checkMileageMerchant
     */
    @Override
    public void updateRestrictionMerchant(CheckMileageMerchant checkMileageMerchant) {
        logger.info("updateRestrictionMerchant");

        getSqlMapClientTemplate().update("CHECKMILEAGE_MERCHANTS.updateRestrictionMerchant", checkMileageMerchant);
    }

    /**
     * 가맹점의 활성화 여부를 업데이트 한다.
     *
     * @param checkMileageMerchant
     */
    @Override
    public void updateDeactivateMerchant(CheckMileageMerchant checkMileageMerchant) {
        logger.info("updateDeactivateMerchant");

        getSqlMapClientTemplate().update("CHECKMILEAGE_MERCHANTS.updateDeactivateMerchant", checkMileageMerchant);
    }

    /**
     * 가맹점 매장 Tablet PC 홍보 문구와 사진을 업데이트 한다.
     *
     * @param checkMileageMerchant
     */
    @Override
    public void updatePRMerchant(CheckMileageMerchant checkMileageMerchant) {
        logger.info("updatePRMerchant");

        getSqlMapClientTemplate().update("CHECKMILEAGE_MERCHANTS.updatePRMerchant", checkMileageMerchant);
    }

    /**
     * 가맹점의 위치 정보를 업데이트 한다.
     *
     * @param checkMileageMerchant
     */
    @Override
    public void updateMerchantLocation(CheckMileageMerchant checkMileageMerchant) {
        logger.info("updateMerchantLocation");

        getSqlMapClientTemplate().update("CHECKMILEAGE_MERCHANTS.updateMerchantLocation", checkMileageMerchant);
    }

    /**
     * 가맹점 검색 결과 목록을 가져 온다.
     *
     * @param checkMileageMerchant
     * @return
     */
    @Override
    public List<CheckMileageMerchant> selectSearchMerchantList(CheckMileageMerchant checkMileageMerchant) {
        logger.info("selectSearchMerchantList");

        return this.getSqlMapClientTemplate().queryForList("CHECKMILEAGE_MERCHANTS.selectSearchMerchantList", checkMileageMerchant);
    }

    /**
     * 모든 가맹점 목록을 가져 온다.(JSon 테스트용도)
     *
     * @param
     * @return
     */
    @Override
    public List<CheckMileageMerchant> selectMerchantList() {
        logger.info("selectMerchantList");

        return this.getSqlMapClientTemplate().queryForList("CHECKMILEAGE_MERCHANTS.selectMerchantList");
    }
}
